#ifndef __GWINTERLOCK_H__
#define __GWINTERLOCK_H__

/**
*@file       gwinterlock.h
*@brief      global function impl inter lock operation
*
*@author     graywind
*@version    1.0.0.0
*@data       2011/11/30
*/

#ifdef WIN32
#include <intrin.h>

class gwInterlock
{
public:
	///@brief     impl atomic operate to exchange thes val
	static long Exchange(long* pTarget, long val)
	{
		return InterlockedCompareExchange(pTarget,val,*pTarget);
	}
};



#else

class gwInterlock
{
public:
	///@brief     impl atomic operate to exchange thes val
	static long Exchange(long* pTarget, long val)
	{
		return __sync_val_compare_and_swap(pTarget, *pTarget, val);
	}
};

#endif


#endif
